<template>
    <div id="i18NButton">
      <ul>
        <li>
          <button @click="changeLang('cn')">
            中文
          </button>
          <span>|</span>
          <button  @click="changeLang('en')">
            English
          </button>
        </li>
      </ul>
    </div>
</template>

<script>
    export default {
        name: "i18NButton",
      methods:{
        changeLang:function (item) {
          this.$i18n.locale = item;
          window.sessionStorage.setItem('i18n',item);
          window.sessionStorage.setItem('lang',item);
          this.$store.dispatch('toChangeLang',item);
          //this.getJson(item);
          //this.getTheLinks(item);
          if(this.$store.getters.getNowPage==='/NewsDetails'){
            this.$store.dispatch('toChangeNowPage','/theNewsList');
          }
          location.reload();
        },
        //重新获取友情链接
        getTheLinks(lang){
          let _this=this;
          this.axios.get(domain.url+'system/api/get_link', {
            params: {
              language:lang,
            }
          })
            .then(function (response) {
              _this.$store.dispatch('toChangeLinksProduct',response.data.link[0]);
            })
            .catch(function (error) {
              console.log(error);
            });
        },
        //重新获取产品导航栏的产品
        getJson(lang){
          let _this=this;
          this.axios.get(domain.url+'system/api/get_nav_bar', {
            params: {
              language:lang
            }
          })
            .then(function (response) {
              _this.$store.dispatch('toChangeSearchProduct',response.data.product);
            })
            .catch(function (error) {
              console.log(error);
            });
        }
      }
    }
</script>

<style scoped>
#i18NButton{
  text-align: center;
  padding-top:25px;
  padding-bottom: 50px;
}
  #i18NButton ul li button{
    border:0;
    background: rgba(0,0,0,0);
    font-weight: 200;
    font-size: 15px;
  }
</style>
